<template>
	<view class="container">
		<header-view type="second" leftShow rightShow>{{type=="login"? $t('登录密码') : $t('支付密码') }}</header-view>
		<view class="content">
			<view class="list flex" v-if="type=='login'">
				<view class="name flex">{{$t('旧密码：')}}</view>
				<u--input :placeholder="$t('请输入旧密码')" border="none" v-model="oldPassword" type="text" color="#fff"
					placeholderStyle="{color:'grey'}"></u--input>
			</view>
			<view class="list flex" v-else>
				<view class="name flex">{{$t('旧密码')}}：</view>
				<u--input :placeholder="$t('请输入旧密码')" border="none" v-model="oldPayment" type="text" color="#fff"
					placeholderStyle="{color:'grey'}"></u--input>
			</view>
			
			<view class="list flex">
				<view class="name flex">{{$t('新密码：')}}</view>
				<u--input :placeholder="$t('请输入新密码')" border="none" v-model="password" type="text" color="#fff"
					placeholderStyle="{color:'grey'}"></u--input>
			</view>
			<view class="list flex">
				<view class="name flex">{{$t('新密码：')}}</view>
				<u--input :placeholder="$t('请再次输入新密码')" border="none" v-model="newPassword" type="text" color="#fff"
					placeholderStyle="{color:'grey'}"></u--input>
			</view>
			<u-button class="submit" :text="$t('提交')" @tap="submit"></u-button>
		</view>
	</view>
</template>

<script>
	import headerView from "@/components/headerView/index.vue"
	import { updataPassApi , updateSecurityApi } from '@/api/api.js'
	export default {
		components: {
			headerView
		},
		data() {
			return {
				//type: "login",
				oldPassword: "",
				password: "",
				newPassword: "",
				oldPayment:''
			};
		},
		onLoad(opt) {
			this.type = opt.type
		},

		methods: {
			
			submit(){
				if(this.type==="login"){
					if(!this.oldPassword){
						uni.$u.toast(this.$t('请输入旧密码'))
					}
					if(!this.password){
						uni.$u.toast(this.$t('请输入新密码'))
					}
					if(!this.newPassword){
						uni.$u.toast(this,$t('请再次输入新密码'))
					}
					if(this.password !== this.newPassword){
						uni.$u.toast(this.$t('两次输入不一致，请重新输入'))
					}
					
					let data={
						old_pass:this.oldPassword,
						new_pass:this.newPassword,
					}
					updataPassApi(data).then(res=>{
						console.log(res.data,"修改登录密码")
						uni.showToast({
							title: res.data.msg,
							icon: "none",
						})
					})
				}
				
				else{
					if(!this.oldPassword){
						uni.$u.toast(this.$t('请输入旧密码'))
					}
					if(!this.password){
						uni.$u.toast(this.$t('请输入新密码'))
					}
					if(!this.newPassword){
						uni.$u.toast(this,$t('请再次输入新密码'))
					}
					if(this.password !== this.newPassword){
						uni.$u.toast(this.$t('两次输入不一致，请重新输入'))
					}
					let data={
						old_pass:this.oldPayment,
						new_pass:this.newPassword,
					}
					updateSecurityApi(data).then(res=>{
						console.log(res.data,"修改支付密码")
						uni.showToast({
							title: res.data.msg,
							icon: "none",
						})
					})
					
				}
				
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.container {

		.content {
			padding: 0 24rpx;

			.list {
				height: 100rpx;
				background: #1f2039;
				border-radius: 20rpx;
				margin-bottom: 30rpx;
				padding: 0 20rpx;

				.name {
					width: 150rpx;
					height: 100rpx;
					font-size: 32rpx;
					font-weight: 400;
					color: #fefefe;
				}

				.u-input {
					flex: 1;
					height: 100rpx;
					line-height: 100rpx;
				}
			}


			.submit {
				height: 88rpx;
				background: #4c3d89;
				border-radius: 44rpx;
				font-size: 32rpx;
				font-weight: 400;
				color: #fff;
				margin-top: 66rpx;
				border: none;
			}
		}
	}
</style>